/**
 * 
 */
package anyware.common.restlet.resource;

import java.util.Calendar;

import org.restlet.Filter;
import org.restlet.data.Form;
import org.restlet.data.Request;
import org.restlet.data.Response;

/**
 * TODO: doc me
 * 
 * @author keke<keke@codehaus.org>
 * @revision $Revision: 103 $
 * @version
 */
public class GWTFolderFilter extends Filter {

	@Override
	protected void afterHandle(final Request request, final Response response) {
		super.afterHandle(request, response);
		Form form = (Form) response.getAttributes().get(
		        "org.restlet.http.headers");
		if (form == null) {
			form = new Form();
			response.getAttributes().put("org.restlet.http.headers", form);
		}
		if (response.getEntity() != null) {
			if (request.getResourceRef().getPath().indexOf(".nocache.") != -1) {
				form.set("Pragma", "no-cache", true);
			} else {
				form.set("Cache-Control", "max-age=31536000", true);
				final Calendar calendar = Calendar.getInstance();
				calendar.add(Calendar.YEAR, 1);
				response.getEntity().setExpirationDate(calendar.getTime());
			}
		}
	}
}
